from django.db import models
from chushi.models import Chushi
from job.models import Job
from rank.models import Rank
from level.models import Level

"""
ORM（Object Ralational Mapping，对象关系映射）
把关系模型表示的表映射到Python的类中
以便在操作实体的时候，就不需要再去编写SQL，只需操作Python对象。
"""


# Create your models here.
class Person(models.Model):
    GENDER_CHOICES = [
        ("M", "男"),
        ("F", "女"),
    ]

    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=255, blank=True, null=True)
    birth_date = models.DateTimeField(blank=True, null=True)
    password = models.CharField(max_length=16, blank=True, null=True)
    sex = models.CharField(max_length=3, choices=GENDER_CHOICES, blank=True, null=True)
    chushi_id = models.ForeignKey(
        Chushi, on_delete=models.CASCADE, related_name="person", blank=True, null=True
    )
    rank_id = models.ForeignKey(
        Rank, on_delete=models.CASCADE, related_name="person", blank=True, null=True
    )
    level_id = models.ForeignKey(
        Level, on_delete=models.CASCADE, related_name="person", blank=True, null=True
    )

    class RoleType(models.TextChoices):  # 会议类型
        LEADER = "领导"
        FOLLOWER = "员工"

    role = models.CharField(
        max_length=6,
        choices=RoleType.choices,
        default=RoleType.FOLLOWER,
        blank=True,
        null=True,
    )
